import request from './request'

const baseURL = import.meta.env.VITE_API_URL

export const uploadAPI = {
  uploadPost(file) {
    const formData = new FormData();
    formData.append('file', file); // 字段名与后端 Multer 的 upload.single('file') 一致
    return request.post(baseURL + '/uploads/post_image', formData);
  },
  uploadImages(files) {
    const uploadPromises = files.map(file =>
      this.uploadPost(file).then(res => res.url)
    );
    return Promise.all(uploadPromises);
  },
  uploadCharacter(file) {
    const formData = new FormData();
    formData.append('file', file); // 字段名与后端 Multer 的 upload.single('file') 一致
    return request.post(baseURL + '/uploads/character_image', formData);
  },
  uploadCharacterImages(files) {
    const uploadPromises = files.map(file =>
      this.uploadCharacter(file).then(res => res.url)
    );
    return Promise.all(uploadPromises);
  }
}